/*
ID: pallab81
PROG:
LANG: C++
*/

//"I have not failed, I have just found 10000 ways that won't work.

#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define foR(i1,st,ed) for(int i1 = st,j1 = ed ; i1 < j1 ; ++i1 )
#define fo(i,ed) foR( i , 0 , ed )
#define foE(i,st,ed) foR( i , st , ed+1 )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip( X ) sleep( X )
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define line puts("")

template<class T1>
inline void debug(T1 _x) {
    cout<<_x<<'\n';
}
template<class T1, class T2>
inline void debug(T1 _x,T2 _y) {
    cout<<_x<<' '<<_y<<'\n';
}
template<class T1, class T2, class T3>
inline void debug(T1 _x,T2 _y,T3 _z) {
    cout<<_x<<' '<<_y<<' '<<_z<<'\n';
}
template<class T1, class T2, class T3, class T4>
inline void debug(T1 _x,T2 _y,T3 _z,T4 _zz) {
    cout<<_x<<' '<<_y<<' '<<_z<<' '<<_zz<<'\n';
}
template< class T1>
inline void debug(T1 _array,int _size) {
    cout<<"[";
    for (int i=0; i<_size; ++i) {
        cout<<' '<<_array[i];
    }
    puts(" ]");
}

class MakeSquare {
public:
    int minChanges(string S);
};
string a, b;
int la,lb;
const int inf=(int)1023456789;
int dp[61][61];
/*
int go(int i,int j) {
    if(i>=la&&j>=lb) {
        return 0;
    }
    int &c=dp[i][j];
    if(c!=-1)return c;
    c=inf;

    if(i>=la&&j<lb) {
        c=min(c,1+go(i,j+1));
    } else if(i<la&&j>=lb) {
        c=min(c,1+go(i+1,j));
    } else {
        if(a[i]==b[j]) {
            c=min(c,go(i+1,j+1));
        }
        c=min(c, min( go(i+1,j+1),
                      min( go(i+1,j), go(i,j+1) )
                    )+1 );
    }
    return c;
}
*/
inline int triplet(int p,int q, int r) {
    return min(p, min(q,r) );
}
int solve() {
    SET(dp,63);
    for(int i=la; i>=0; --i) {
        for(int j=lb; j>=0; --j) {
            if(i==la&&j==lb) {
                dp[i][j]=0;
            } else if(i==la&&j<lb) {
                dp[i][j]=min(dp[i][j],dp[i][j+1]+1);
            } else if(i<la&&j==lb) {
                dp[i][j]=min(dp[i][j],dp[i+1][j]+1);
            } else {
                if(a[i]==b[j]) {
                    dp[i][j]=min(dp[i][j], dp[i+1][j+1] );
                }
                dp[i][j]=min(dp[i][j], triplet( dp[i+1][j+1],dp[i+1][j], dp[i][j+1] )+1 );
            }
        }
    }
    return dp[0][0];
}
int MakeSquare :: minChanges(string S) {

    int best=inf;
    foE(i,0,LN(S)) {
        a = S.substr(0,i);
        b = S.substr(i);
        la=LN(a);
        lb=LN(b);
        best=min(best, solve() );

    }
    return best;
}
// BEGIN KAWIGIEDIT TESTING
// Generated by KawigiEdit 2.1.8 (beta) modified by pivanof
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool KawigiEdit_RunTest(int testNum, string p0, bool hasAnswer, int p1) {
    cout << "Test " << testNum << ": [" << "\"" << p0 << "\"";
    cout << "]" << endl;
    MakeSquare *obj;
    int answer;
    obj = new MakeSquare();
    clock_t startTime = clock();
    answer = obj->minChanges(p0);
    clock_t endTime = clock();
    delete obj;
    bool res;
    res = true;
    cout << "Time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " seconds" << endl;
    if (hasAnswer) {
        cout << "Desired answer:" << endl;
        cout << "\t" << p1 << endl;
    }
    cout << "Your answer:" << endl;
    cout << "\t" << answer << endl;
    if (hasAnswer) {
        res = answer == p1;
    }
    if (!res) {
        cout << "DOESN'T MATCH!!!!" << endl;
    } else if (double(endTime - startTime) / CLOCKS_PER_SEC >= 2) {
        cout << "FAIL the timeout" << endl;
        res = false;
    } else if (hasAnswer) {
        cout << "Match :-)" << endl;
    } else {
        cout << "OK, but is it right?" << endl;
    }
    cout << "" << endl;
    return res;
}
int main() {
    bool all_right;
    all_right = true;

    string p0;
    int p1;

    {
        // ----- test 0 -----
        p0 = "abcdabgcd";
        p1 = 1;
        all_right = KawigiEdit_RunTest(0, p0, true, p1) && all_right;
        // ------------------
    }

    {
        // ----- test 1 -----
        p0 = "abcdeabce";
        p1 = 1;
        all_right = KawigiEdit_RunTest(1, p0, true, p1) && all_right;
        // ------------------
    }

    {
        // ----- test 2 -----
        p0 = "abcdeabxde";
        p1 = 1;
        all_right = KawigiEdit_RunTest(2, p0, true, p1) && all_right;
        // ------------------
    }

    {
        // ----- test 3 -----
        p0 = "aabcaabc";
        p1 = 0;
        all_right = KawigiEdit_RunTest(3, p0, true, p1) && all_right;
        // ------------------
    }

    {
        // ----- test 4 -----
        p0 = "aaaaabaaaaabaaaaa";
        p1 = 2;
        all_right = KawigiEdit_RunTest(4, p0, true, p1) && all_right;
        // ------------------
    }

    if (all_right) {
        cout << "You're a stud (at least on the example cases)!" << endl;
    } else {
        cout << "Some of the test cases had errors." << endl;
    }
    return 0;
}
// END KAWIGIEDIT TESTING


//Powered by KawigiEdit 2.1.8 (beta) modified by pivanof!
